
Utility = {
    setPageChanged: function(){
        PAGE_CHANGED = true;
        return this;
    },

    unsetPageChanged: function(){
        delete PAGE_CHANGED;
        return this;
    },


    /** get current url excluding any request param **/
    getCurrentUrl: function(){
      return location.protocol +'//'+ location.hostname + ':' + location.port + location.pathname;
    },


    postData: function(aUrl, aData, aType){

      var type = (typeof(aType)=='undefined')? 'post' : aType;

      var form = document.createElement("form");
      form.method= type ;
      form.action = aUrl ;
      for (var key in aData) {
        var formfield = document.createElement("input") ;
        formfield.setAttribute("name", key) ;
        formfield.setAttribute("value", aData[key]);
        form.appendChild(formfield) ;
      }
      document.body.appendChild(form) ;
      form.submit() ;
    },


    init: function(){
        this.registerPrototypes();
        return this;
    },

    registerPrototypes: function(){
        /**Add json printf functionality to string objects */
        String.prototype.jsonPrintf = function(obj) {
          var formatted = new String(this);
          for(key in obj) {
            formatted = formatted.split("{" + key + "}").join(obj[key]);
          }
          return formatted;
        };

        String.prototype.contains = function(aVal) {
          return this.indexOf(aVal) != -1;
        };

        return this;
    },

    getPaddedWithZero: function(aVal, aLength){
      var zeros = "0000000000000000";
      if(aVal.length == aLength){
        return aVal;
      }
      else{
        var padBy = aLength - aVal.length;
        return zeros.substr(0,padBy) + aVal;
      }
    },

}.init(); //call constructor